{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>Derived Distributions</h2>\n",
    "\n",
    "Consider the random variable $Y=g\\left(X\\right)\\hspace{1pt}$ where *X* is a continuous RV. Assuming the PDF of *X* is known, the PDF of *Y* can be obtained as follows:\n",
    "\n",
    "1. Calculate the CDF $F_Y\\hspace{1pt}$ of *Y* using the formula <br/><br/>\n",
    "$$F_Y\\left(y\\right) = P\\left(g\\left(X\\right)\\le y\\right) = \\int_{\\left\\{x \\vert g\\left(x\\right)\\le y \\right\\}}f_X\\left(x\\right)dx$$<br/>\n",
    "2. Differentiate to obtain the PDF of *Y*:\n",
    "\n",
    "$$f_Y\\left(y\\right) = \\frac{dF_Y}{dy}\\left(y\\right)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3>The Linear Case</h3>\n",
    "Let *X* be a continuous RV with PDF $f_X\\hspace{1pt}$, and let\n",
    "\n",
    "$$Y= aX + b$$\n",
    "\n",
    "where *a* and *b* are scalars with $a\\ne 0\\hspace{1pt}$, then the PDF of *Y* is\n",
    "\n",
    "$$f_Y\\left(y\\right) = \\frac{1}{\\left|a\\right|}f_X\\left(\\frac{y-b}{a}\\right)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3>Strictly Monotonic Functions of a Continuous RV</h3>\n",
    "Suppose $g\\left(X\\right)\\hspace{1pt}$ is strictly monotonic and that $h\\left(y\\right)$ is the inverse of *g* over the range of *X*, (all *X=x* with positive probability density) and that *h* is differentiable then the PDF of $Y=g\\left(X\\right)\\hspace{1pt}$ is\n",
    "\n",
    "$$f_Y\\left(y\\right) = f_X\\left(h\\left(y\\right)\\right) \\left| \\frac{dh}{dy}\\left(y\\right)\\right|$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3>Sums/Differences of Independent RVs</h3>\n",
    "Consider the RV $Z=X+Y\\hspace{1pt}$ where *X* and *Y* are **independent** random variables. \n",
    "\n",
    "Suppose first that *X* and *Y*, and therefore *Z*, are **integer valued**. The PMF of *Z*, $p_Z\\hspace{1pt}$, is the convolution of the PMFs of *X* and *Y*\n",
    "\n",
    "$$p_Z\\left(z\\right) = P\\left(X+Y=z\\right) = \\sum_x p_X\\left(x\\right)p_Y\\left(z-x\\right)$$\n",
    "\n",
    "Now consider the cae where *X* and *Y* are continuous RVs with PDFs $f_x\\hspace{1pt}$ and $f_y\\hspace{1pt}$, respectively, then the PDF of *Z*, is again a convolution\n",
    "\n",
    "$$f_Z\\left(z\\right) = \\int_{-\\infty}^{\\infty} f_{X,Z}\\left(x,z\\right)dz = \\int_{-\\infty}^{\\infty} f_X\\left(x\\right)f_Y\\left(z-x\\right)$$\n",
    "\n",
    "For the RV $Z=X-Y\\hspace{1pt}$, the PDF of *Z* is\n",
    "\n",
    "$$f_Z\\left(z\\right) = \\int_{-\\infty}^{\\infty} f_X\\left(x\\right)f_Y\\left(x-z\\right)$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>Covariance and Correlation</h2>\n",
    "<h3>Covariance</h3>\n",
    "Consider two RVs *X* and *Y*. The **covariance** of *X* and *Y* is defined as \n",
    "\n",
    "$$cov\\left(X,Y\\right) = E\\left[ \\left(X-E\\left[X\\right]\\right) \\left(Y-\\left[Y\\right]\\right)\\right] = E\\left[XY\\right] - E\\left[X\\right]E\\left[Y\\right]$$\n",
    "\n",
    "The covariance has the following properties:\n",
    "\n",
    "* For any RVs *X, Y, Z* and scalars *a, b* we have\n",
    "\n",
    "$$cov\\left(X,X\\right) = var\\left(X\\right)$$\n",
    "\n",
    "$$cov\\left(X,aY+b\\right) = a \\cdot cov\\left(X,Y\\right)$$\n",
    "\n",
    "$$cov\\left(X, Y + Z \\right) = cov\\left(X,Y\\right) + cov\\left(X,Z\\right)$$\n",
    "\n",
    "* If $cov\\left(X,Y\\right)=0\\hspace{1pt}$, *X* and *Y* are said to be uncorrelated\n",
    "\n",
    "* If *X* and *Y* are *independent*, they are uncorrelated. The converse does not hold in general."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3>Correlation</h3>\n",
    "For two RVs *X* and *Y*, the **correlation coefficient**, $\\rho\\left(X,Y\\right)\\hspace{1pt}$ is defined as \n",
    "\n",
    "$$\\rho\\left(X,Y\\right) = \\frac{cov\\left(X,Y\\right)}{\\sqrt{var\\left(X\\right)var\\left(Y\\right)}}$$\n",
    "\n",
    "and is bounded by $-1\\le \\rho \\le 1\\hspace{1pt}$\n",
    "\n",
    "In the case that $\\left|\\rho\\right| = 1 \\hspace{1pt}$, then there exists a constant *c* such that\n",
    "\n",
    "$$Y-E\\left[Y\\right] = c\\left(X-E\\left[X\\right]\\right)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
